import React from 'react';
import { View, Text } from '@tarojs/components';
import './index.less';

export interface LoadingSpinnerProps {
  /** 提示文字，不传或空则不显示 */
  text?: string;
}

const LoadingSpinner: React.FC<LoadingSpinnerProps> = ({ text }) => {
  if (!text) {
    return null;
  }
  // 花瓣数12
  const petals = Array.from({ length: 12 });
  return (
    <View className="loading-modal-overlay">
      <View className="loading-modal-container">
        <View className="petal-spinner">
          {petals.map((_, i) => (
            <View key={i} className="petal" />
          ))}
        </View>
        <Text className="loading-text">{text}</Text>
      </View>
    </View>
  );
};

export default LoadingSpinner;
